/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
 */

package org.opengauss.vo;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * description:this for BlobTypeHandler Class
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021.
 *
 * @author Administrator
 * @version [openGauss_debug 0.0.1 2021/3/12]
 * @since 2021/3/12
 */
public class ByteaTypeHandler extends BaseTypeHandler {
    public static AtomicInteger blobFileId = new AtomicInteger(0);
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, Object o, JdbcType jdbcType) throws SQLException {
        preparedStatement.setBytes(i, ((String) (o)).getBytes(StandardCharsets.UTF_8));
    }

    @Override
    public Object getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return new String(resultSet.getBytes(s));
    }

    @Override
    public Object getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return new String(resultSet.getBytes(i));
    }

    @Override
    public Object getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return new String(callableStatement.getBytes(i));
    }
    
    @Override
    public Object getResult(final ResultSet rs, final int columnIndex) throws SQLException {
        return super.getResult(rs, columnIndex);
    }
}
